<?php

/*
	info: 商铺管理
	date: 2011-12-04
*/

if (!defined('ADMIN_WEBINROOT'))
{
	header("HTTP/1.0 404 Not Found");
	exit();
}

require WEBFILEPATH.'/include/category.class.php';
$webglobal['file_company'] = array();
$webglobal['file_company']['imagepath'] = '/upfiles/company/'.global_FormatTime(0, 'Ym');
$webglobal['file_company']['logosetting'] = $webglobal['file_company']['bcodesetting'] = array('type'=>array('gif', 'jpg', 'jpeg', 'png', 'bmp'), 'size'=>2097152);

$categoryDataModel = CategoryDataModel::factory('company', array('cache' => true));
$webglobal['file_company']['category'] = $categoryDataModel->formatCategoryOption(0,0);
$areaDataModel = CategoryDataModel::factory('area', array('cache' => true));
$webglobal['file_company']['areadata'] = $areaDataModel->formatCategoryOption(0,0);
$webglobal['file_company']['citydata'] = $areaDataModel->getCategoryForLevel(1);

//商铺编辑
if ($webglobal['mode']=='companyedit')
{
	$webrequest['editid'] = isset($webrequest['editid']) ? intval($webrequest['editid']) : 0;
	if ($webrequest['editid'] <= 0)
	{
		admin_ShowMessage('不存在该商铺。', '', 'BACK');
	}
	$webglobal['file_company']['editinfo'] = $db->GetOne("SELECT * FROM {$webconfig['dbpre']}company WHERE id='{$webrequest['editid']}'");

	if (!$webglobal['file_company']['editinfo'])
	{
		admin_ShowMessage('不存在该商铺。', '', 'BACK');
	}

	if (global_CheckSubmit('adminsubmit'))
	{
		include WEBFILEPATH.'/include/upload.class.php';
		global_CheckPost(
				array(
					array('company_category_id,','int','isset($webglobal[\'file_company\'][\'category\'][@])','请选择商铺分类',1),
					array('status,','int','in_array(@, array(1,0,-1))','请选择商铺状态',1),
					array('newstar,','int','','',0,0),
					array('username,','username','','用户名只能为字母开头的数字字母组合，长度不超过15位',1),
					array('email,','email','','email格式不合法',1),
					array('name,','str','','',0,''),
					array('english_name,','str','','',0,''),
					array('logo_del','int','','',0,0),
					array('bcode,','str','','',0,''),
					array('bcode_image_del','int','','',0,0),
					array('address,','str','','商铺地址不能为空',1),
					array('tel,','str','','',0,''),
					array('latitude,','','preg_match("/^[0-9]+\.[0-9]+$/", @)','',0,0),
					array('longitude,','','preg_match("/^[0-9]+\.[0-9]+$/", @)','',0,0),
					array('site,','url','','',0,''),
					array('description,','','','商铺介绍不能为空',1),
					array('area_id','int','','请选择对应的商圈',1),
			));
		if ($webglobal['CPP']['name']=='' && $webglobal['CPP']['english_name']=='')
		{
			$webglobal['CPM'][] = '商铺中文名称和英文名称必填一个';
		}

		if (!isset($webglobal['file_company']['areadata'][$webglobal['CPP']['area_id']])) {
			$webglobal['CPM'][] = '系统中不存在该商圈';
		}
		if ($webglobal['file_company']['areadata'][$webglobal['CPP']['area_id']]['level'] != 3) {
			$webglobal['CPM'][] = '所选择的商圈不合法';
		} else {
			$webglobal['CPD']['area_id'] = $webglobal['CPP']['area_id'];
			$parentArea = $webglobal['file_company']['areadata'][$webglobal['CPP']['area_id']]['upCategoryID'];
			foreach ($parentArea as $areaId) {
				if (isset($webglobal['file_company']['areadata'][$areaId])) {
					switch ($webglobal['file_company']['areadata'][$areaId]['level']) {
						case 0:
							$webglobal['CPD']['province'] = $areaId;
							break;
						case 1:
							$webglobal['CPD']['city'] = $areaId;
							break;
						case 2:
							$webglobal['CPD']['district'] = $areaId;
							break;
					}
				}
			}
		}
		$checkarray = array();
		if (!empty($webglobal['CPP']['username']) && $webglobal['CPP']['username']!=$webglobal['file_company']['editinfo']['username'])
		{
			$checkarray[] = "username='{$webglobal['CPP']['username']}'";
		}
		if (!empty($webglobal['CPP']['email']) && $webglobal['CPP']['email']!=$webglobal['file_company']['editinfo']['email'])
		{
			$checkarray[] = "email='{$webglobal['CPP']['email']}'";
		}
		if (!empty($webglobal['CPP']['name']) && $webglobal['CPP']['name']!=$webglobal['file_company']['editinfo']['name'])
		{
			$checkarray[] = "name='{$webglobal['CPP']['name']}'";
		}
		if (!empty($webglobal['CPP']['english_name']) && $webglobal['CPP']['english_name']!=$webglobal['file_company']['editinfo']['english_name'])
		{
			$checkarray[] = "english_name='{$webglobal['CPP']['english_name']}'";
		}
		if (!empty($webglobal['CPP']['bcode']) && $webglobal['CPP']['bcode']!=$webglobal['file_company']['editinfo']['bcode'])
		{
			$checkarray[] = "bcode='{$webglobal['CPP']['bcode']}'";
		}
		if (!empty($checkarray))
		{
			$temphave = $db->GetNum("SELECT COUNT(*) FROM {$webconfig['dbpre']}company WHERE id!='{$webrequest['editid']}' AND (".implode(' OR ', $checkarray).")");
			if ($temphave > 0)
			{
				$webglobal['CPM'][] = '用户名、email、商铺中文名称、商铺英文名称或营业执照数据库中已存在';
			}
		}

		if (!empty($webglobal['CPM']))
		{
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			include WEBFILEPATH.'/include/image.class.php';
			$objImg = new Image();
			$tempmoreshowinfo = $templogourl = $tempbcodeurl = '';
			$templogoupload = new Upload('logo', $webglobal['file_company']['logosetting']);
			if ($templogoupload->CheckFile())
			{
				$templogoupload->SaveFile(WEBFILEPATH.$webglobal['file_company']['imagepath']);
				$templogourl = $webglobal['file_company']['imagepath'].'/'.$templogoupload->fileList[0]['name'];

				//缩放logo
				//生成缩略图
				$imageFilePath = WEBFILEPATH.$webglobal['file_company']['imagepath'] . '/' . $templogoupload->fileList[0]['name'];

				//Big Image:205 133
				$smallImage = WEBFILEPATH.$webglobal['file_company']['imagepath'] . '/small_' . $templogoupload->fileList[0]['name'];
				$objImg->OnceResize($imageFilePath , 100 , 100 , $smallImage, 5, FALSE);
			} elseif (!$templogoupload->isNone) {
				$tempmoreshowinfo .= '<br /><span class="dark">上传的logo文件不符合条件已忽略。</span>';
			}

			$tempbcodeupload = new Upload('bcode_image', $webglobal['file_company']['bcodesetting']);
			if ($tempbcodeupload->CheckFile())
			{
				$tempbcodeupload->SaveFile(WEBFILEPATH.$webglobal['file_company']['imagepath']);
				$tempbcodeurl = $webglobal['file_company']['imagepath'].'/'.$tempbcodeupload->fileList[0]['name'];
			}
			elseif (!$tempbcodeupload->isNone)
			{
				$tempmoreshowinfo .= '<br /><span class="dark">上传的营业执照文件不符合条件已忽略。</span>';
			}

			if ($webglobal['CPP']['logo_del']>0 || $templogourl!='')
			{
				if ($webglobal['file_company']['editinfo']['logo'] != '')
				{
					@unlink(WEBFILEPATH.$webglobal['file_company']['editinfo']['logo']);
				}
				$webglobal['CPD']['logo'] = $templogourl;
			}

			if ($webglobal['CPP']['bcode_image_del']>0 || $tempbcodeurl!='')
			{
				if ($webglobal['file_company']['editinfo']['bcode_image'] != '')
				{
					@unlink(WEBFILEPATH.$webglobal['file_company']['editinfo']['bcode_image']);
				}
				$webglobal['CPD']['bcode_image'] = $tempbcodeurl;
			}

			admin_CheckFromForm(ADMIN_WEBURLPATH."/index.php?mode=company&{$webrequest['gourl']}");
			$db->Update('company', '', "id='{$webrequest['editid']}'");
			//取消其他商铺的明星商铺属性
			if (isset($webglobal['CPD']['newstar']) && $webglobal['CPD']['newstar']) {
				$db->Update('company', "newstar=0", 'id != '.$webrequest['editid'].' AND city != '.$webglobal['file_company']['editinfo']['city']);
				$resizeImage = isset($webglobal['CPD']['logo']) && $webglobal['CPD']['logo'] != '' ? $imageFilePath : WEBFILEPATH.$webglobal['file_company']['editinfo']['logo'];

				$dirPath = dirname($resizeImage);
				$filename = basename($resizeImage);

				$starImage = $dirPath . '/star_' . $filename;
				$objImg->OnceResize($resizeImage , 215 , 129 , $starImage, 0, FALSE);
			}

			cache_GetCompanyDetail($webrequest['editid'], true, false);
			cache_GetNewCompany(false, true);

			admin_AddLog("修改商铺|id: {$webrequest['editid']}");
			admin_ShowMessage("商铺修改成功。{$tempmoreshowinfo}", ADMIN_WEBURLPATH."/index.php?mode=company&{$webrequest['gourl']}");
		}
	}
	else
	{
		$webglobal['file_company']['gourlencode'] = urlencode($webrequest['gourl']);
		$webglobal['file_company']['editinfo']['logintime_show'] = !empty($webglobal['file_company']['editinfo']['logintime']) ? global_FormatTime($webglobal['file_company']['editinfo']['logintime']) : '';
		$webglobal['file_company']['editinfo']['addtime_show'] = global_FormatTime($webglobal['file_company']['editinfo']['addtime']);

		//商圈json数据
		$webglobal['file_company']['editinfo']['area_json'] = $areaDataModel->formatClassToJson(0, 0);
		$webglobal['file_company']['editinfo']['area_tree'] = '';
		if (isset($webglobal['file_company']['areadata'][$webglobal['file_company']['editinfo']['area_id']])) {
			$parentArea = $webglobal['file_company']['areadata'][$webglobal['file_company']['editinfo']['area_id']]['upCategoryID'];
			array_shift($parentArea);
			$webglobal['file_company']['editinfo']['area_tree'] = implode(',', $parentArea) . ',' .$webglobal['file_company']['editinfo']['area_id'];
		}
		admin_StartFromForm();
	}
}

//彻底删除
elseif ($webglobal['mode']=='companydel')
{
	if (!global_CheckCome())
	{
		admin_ShowMessage('参数错误。', '', 'BACK');
	}

	$webrequest['id'] = isset($webrequest['id']) ? intval($webrequest['id']) : 0;
	if ($webrequest['id'] <= 0)
	{
		admin_ShowMessage('不存在该商铺。', '', 'BACK');
	}
	$webglobal['file_company']['editinfo'] = $db->GetOne("SELECT * FROM {$webconfig['dbpre']}company WHERE id='{$webrequest['id']}'");
	if (!$webglobal['file_company']['editinfo'])
	{
		admin_ShowMessage('不存在该商铺。', '', 'BACK');
	}
	elseif ($webglobal['file_company']['editinfo']['status']!=-1)
	{
		admin_ShowMessage('只有已删除状态的商铺才能彻底删除！', '', 'BACK');
	}
	$db->Delete('company', "id='{$webrequest['id']}'");
	if ($webglobal['file_company']['editinfo']['logo'] != '')
	{
		@unlink(WEBFILEPATH.$webglobal['file_company']['editinfo']['logo']);
	}
	if ($webglobal['file_company']['editinfo']['bcode_image'] != '')
	{
		@unlink(WEBFILEPATH.$webglobal['file_company']['editinfo']['bcode_image']);
	}
	cache_GetCompanyDetail($webrequest['id'], true, false);
	cache_GetNewCompany(false, true);
	//删除店铺后其他数据的清理
	admin_AddLog("删除商铺|id: {$webrequest['id']}, name: {$webglobal['file_company']['editinfo']['name']}({$webglobal['file_company']['editinfo']['english_name']})");
	admin_ShowMessage('商铺数据彻底删除成功。', ADMIN_WEBURLPATH."/index.php?mode=company&{$webrequest['gourl']}");
}

//批量更改
elseif ($webglobal['mode']=='companyup')
{
	if (!global_CheckCome())
	{
		admin_ShowMessage('参数错误。', '', 'BACK');
	}

	global_CheckPost(
				array(
					array('delid[]','int','',''),
					array('auditid[]','int','',''),
					array('access','str','','',0,'update'),
			));

	$tempauditstr = '';
	if ($webglobal['CPP']['access'] == 'update') {
		if (!empty($webglobal['CPP']['auditid']))
		{
			$tempauditstr = implode(',', $webglobal['CPP']['auditid']);
			$db->Update('company', "status='1'", 'id IN ('.$db->BuildInSql($webglobal['CPP']['auditid']).')');
		}
	}
	

	$tempdelstr = '';
	if ($webglobal['CPP']['access'] == 'delete') {
		if (!empty($webglobal['CPP']['delid']))
		{
			$tempdelstr = implode(',', $webglobal['CPP']['delid']);
			$db->Update('company', "status='-1'", 'id IN ('.$db->BuildInSql($webglobal['CPP']['delid']).')');
		}
	}

	$templogmsg = '';
	if (!empty($tempauditstr))
	{
		$templogmsg .= (empty($templogmsg) ? '' : '; ')."audit: {$tempauditstr}";
		foreach ($webglobal['CPP']['auditid'] as $id) {
			cache_GetCompanyDetail($id, true, false);
		}
	}

	if (!empty($tempdelstr))
	{
		$templogmsg .= (empty($templogmsg) ? '' : '; ')."del: {$tempdelstr}";
		foreach ($webglobal['CPP']['delid'] as $id) {
			cache_GetCompanyDetail($id, true, false);
		}
	}

	cache_GetNewCompany(false, true);

	if (empty($templogmsg))
	{
		admin_ShowMessage("没有任何条目被修改，系统自动返回。", ADMIN_WEBURLPATH."/index.php?mode=company&{$webrequest['gourl']}");
	}

	admin_AddLog("批量更改商铺|{$templogmsg}");
	admin_ShowMessage('批量设置商铺属性成功。', ADMIN_WEBURLPATH."/index.php?mode=company&{$webrequest['gourl']}");
}

//找回密码申请
elseif ($webglobal['mode']=='companyfp')
{
	if (global_CheckSubmit('adminsubmit'))
	{
		global_CheckPost(
				array(
					array('delid[]','int','',''),
					array('auditid[]','int','',''),
			));
		$tempdelstr = '';
		if (!empty($webglobal['CPP']['delid']))
		{
			$tempdelstr = implode(',', $webglobal['CPP']['delid']);
			$db->Delete('find_pwd', 'id IN ('.$db->BuildInSql($webglobal['CPP']['delid']).')');
		}
		$temppassstr = $tempdenystr = '';
		if (!empty($webglobal['CPP']['auditid']))
		{
			$temppassarray = $tempdenyarray = array();
			foreach ($webglobal['CPP']['auditid'] as $tempkey => $tempvalue)
			{
				if ($tempvalue==1)
				{
					$temppassarray[] = $tempkey;
				}
				elseif ($tempvalue==2)
				{
					$tempdenyarray[] = $tempkey;
				}
			}
			if (!empty($tempdenyarray))
			{
				$tempdenystr = implode(',', $tempdenyarray);
				$db->Update('find_pwd', "status='2'", 'id IN ('.$db->BuildInSql($tempdenyarray).')');
			}
			if (!empty($temppassarray))
			{
				$tempsendarray = array();
				include_once WEBFILEPATH.'/include/email.class.php';
				$tempemail = new Email();
				$query = $db->Query("SELECT F.*,C.username AS c_username,C.email AS c_email,C.name AS c_name,C.english_name AS c_english_name FROM {$webconfig['dbpre']}find_pwd F LEFT JOIN {$webconfig['dbpre']}company C ON F.company_id=C.id WHERE F.id IN (".$db->BuildInSql($temppassarray).")");
				while ($tempdata = $db->FetchArray($query))
				{
					if (!empty($tempdata['c_email']))
					{
						$tempactiveurl = "http://{$webserver['webhost']}".WEBURLPATH."/login.php?action=resetpass&code=".global_EncryptKey("1,{$tempdata['company_id']},{$tempdata['id']},{$webserver['timestamp']}", WEBAUTHKEY);
						$tempemail->ClearErrorMsg();
						$tempemail->Send($tempdata['c_email'], "{$webcache['setting']['sitename']} 商家找回密码邮件", "亲爱的{$tempdata['c_username']}：<br />&nbsp;&nbsp;&nbsp;&nbsp;您的找回密码申请已经批准，请点击以下链接重新设置密码，24小时以内有效，如果不能点击请复制以下链接到浏览器地址栏打开。<br /><a href=\"{$tempactiveurl}\" target=\"_blank\">$tempactiveurl</a>", 1);
						if (empty($tempemail->errorMsg))
						{
							$tempsendarray[] = $tempdata['id'];
						}
					}
				}
				if (!empty($tempsendarray))
				{
					$db->Update('find_pwd', "status='1'", 'id IN ('.$db->BuildInSql($tempsendarray).')');
					$temppassstr = implode(',', $tempsendarray);
				}
			}
		}
		$templogmsg = '';
		if (!empty($tempdelstr))
		{
			$templogmsg .= (empty($templogmsg) ? '' : '; ')."del: {$tempdelstr}";
		}
		if (!empty($temppassstr))
		{
			$templogmsg .= (empty($templogmsg) ? '' : '; ')."pass: {$temppassstr}";
		}
		if (!empty($tempdenystr))
		{
			$templogmsg .= (empty($templogmsg) ? '' : '; ')."deny: {$tempdenystr}";
		}
		if (empty($templogmsg))
		{
			admin_ShowMessage("没有任何条目被修改，系统自动返回。", ADMIN_WEBURLPATH."/index.php?mode=companyfp&{$webrequest['gourl']}");
		}

		admin_AddLog("批量更改商铺找回密码申请|{$templogmsg}");
		admin_ShowMessage('批量设置商铺找回密码申请成功。', ADMIN_WEBURLPATH."/index.php?mode=companyfp&{$webrequest['gourl']}");
	}
	else
	{
		global_CheckPost(
				array(
					array('order','str','','',0,''),
					array('searchkey','str','','',0,''),
					array('status','int','','',0,999),
					array('coid','int','','',0,0),
			));

		$tempsearchsql = array();
		$webglobal['file_company']['gourl'] = "page={$webrequest['page']}";
		$webglobal['file_company']['searchurl'] = "";
		if ($webglobal['CPP']['coid'] > 0)
		{
			$tempsearchsql[] = "F.company_id='{$webglobal['CPP']['coid']}'";
			$webglobal['file_company']['gourl'] .= "&coid={$webglobal['CPP']['coid']}";
			$webglobal['file_company']['searchurl'] .= "&coid={$webglobal['CPP']['coid']}";
		}
		if ($webglobal['CPP']['status'] != 999)
		{
			$tempsearchsql[] = "F.status='{$webglobal['CPP']['status']}'";
			$webglobal['file_company']['gourl'] .= "&status={$webglobal['CPP']['status']}";
			$webglobal['file_company']['searchurl'] .= "&status={$webglobal['CPP']['status']}";
		}
		if ($webglobal['CPP']['searchkey'] != '')
		{
			$tempsearchsql[] = $db->BuildSearchSql($webglobal['CPP']['searchkey'], array('F.reason','C.name','C.english_name'));
			$webglobal['file_company']['gourl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
			$webglobal['file_company']['searchurl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
		}
		if ($webglobal['CPP']['order'] != '')
		{
			$webglobal['file_company']['gourl'] .= "&order={$webglobal['CPP']['order']}";
		}
		$tempsearchsql = empty($tempsearchsql) ? '' : ' WHERE '.implode(' AND ', $tempsearchsql);
		$webglobal['file_company']['gourlencode'] = urlencode($webglobal['file_company']['gourl']);

		$webglobal['file_company']['perpage'] = 10;
		$webglobal['file_company']['datanum'] = $db->GetNum("SELECT COUNT(*) FROM {$webconfig['dbpre']}find_pwd F LEFT JOIN {$webconfig['dbpre']}company C ON F.company_id=C.id{$tempsearchsql}");
		if ($webglobal['file_company']['datanum'] > 0)
		{
			$webglobal['page'] = global_Page($webglobal['file_company']['datanum'], $webglobal['file_company']['perpage'], $webrequest['page'], ADMIN_WEBURLPATH."/index.php?mode=companyfp&page=@@");
			$tempstartnum = ($webrequest['page']-1)*$webglobal['file_company']['perpage'];
			$query = $db->Query("SELECT F.*,C.name AS c_name,C.english_name AS c_english_name FROM {$webconfig['dbpre']}find_pwd F LEFT JOIN {$webconfig['dbpre']}company C ON F.company_id=C.id{$tempsearchsql} ORDER BY id DESC LIMIT $tempstartnum, {$webglobal['file_company']['perpage']}");
			$temptr = 1;
			$webglobal['file_company']['dataarray'] = array();
			while ($tempdata = $db->FetchArray($query))
			{
				$tempdata['tdclass'] = (($temptr++)%2==0) ? ' class="evenrow"' : '';
				$tempdata['addtime_show'] = global_FormatTime($tempdata['addtime']);
				$webglobal['file_company']['dataarray'][$tempdata['id']] = $tempdata;
			}
		}
	}
}

//列表
elseif ($webglobal['mode']=='company')
{
	global_CheckPost(
				array(
					array('order','str','','',0,''),
					array('searchkey','str','','',0,''),
					array('class','int','','',0,0),
					array('status','int','','',0,999),
					array('city','int','','',0,0),
			));

	$tempsearchsql = array();
	$webglobal['file_company']['gourl'] = "page={$webrequest['page']}";
	$webglobal['file_company']['searchurl'] = "";
	if ($webglobal['CPP']['class'] > 0)
	{
		$tempsearchsql[] = "company_category_id='{$webglobal['CPP']['class']}'";
		$webglobal['file_company']['gourl'] .= "&class={$webglobal['CPP']['class']}";
		$webglobal['file_company']['searchurl'] .= "&class={$webglobal['CPP']['class']}";
	}
	if ($webglobal['CPP']['status'] != 999)
	{
		$tempsearchsql[] = "status='{$webglobal['CPP']['status']}'";
		$webglobal['file_company']['gourl'] .= "&status={$webglobal['CPP']['status']}";
		$webglobal['file_company']['searchurl'] .= "&status={$webglobal['CPP']['status']}";
	}
	if ($webglobal['CPP']['city'] > 0)
	{
		$tempsearchsql[] = "city='{$webglobal['CPP']['city']}'";
		$webglobal['file_company']['gourl'] .= "&city={$webglobal['CPP']['city']}";
		$webglobal['file_company']['searchurl'] .= "&city={$webglobal['CPP']['city']}";
	}
	if ($webglobal['CPP']['searchkey'] != '')
	{
		$tempsearchsql[] = $db->BuildSearchSql($webglobal['CPP']['searchkey'], array('username','name','english_name','address'));
		$webglobal['file_company']['gourl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
		$webglobal['file_company']['searchurl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
	}
	if ($webglobal['CPP']['order'] != '')
	{
		$webglobal['file_company']['gourl'] .= "&order={$webglobal['CPP']['order']}";
	}
	$tempsearchsql = empty($tempsearchsql) ? '' : ' WHERE '.implode(' AND ', $tempsearchsql);
	$webglobal['file_company']['gourlencode'] = urlencode($webglobal['file_company']['gourl']);

	$webglobal['file_company']['perpage'] = 10;
	$webglobal['file_company']['datanum'] = $db->GetNum("SELECT COUNT(*) FROM {$webconfig['dbpre']}company{$tempsearchsql}");
	if ($webglobal['file_company']['datanum'] > 0)
	{
		$webglobal['page'] = global_Page($webglobal['file_company']['datanum'], $webglobal['file_company']['perpage'], $webrequest['page'], ADMIN_WEBURLPATH."/index.php?mode=company&order={$webglobal['CPP']['order']}{$webglobal['file_company']['searchurl']}&page=@@");
		$tempstartnum = ($webrequest['page']-1)*$webglobal['file_company']['perpage'];
		switch ($webglobal['CPP']['order'])
		{
			case 'id':
				$temporderstr = "id DESC";
				break;
			case 'addtime':
				$temporderstr = "addtime DESC,id DESC";
				break;
			default:
				$temporderstr = "id DESC";
		}
		$query = $db->Query("SELECT * FROM {$webconfig['dbpre']}company{$tempsearchsql} ORDER BY {$temporderstr} LIMIT $tempstartnum, {$webglobal['file_company']['perpage']}");
		$temptr = 1;
		$webglobal['file_company']['dataarray'] = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$tempdata['tdclass'] = (($temptr++)%2==0) ? ' class="evenrow"' : '';
			$tempdata['logintime_show'] = !empty($tempdata['logintime']) ? global_FormatTime($tempdata['logintime']) : '';
			$tempdata['addtime_show'] = global_FormatTime($tempdata['addtime']);
			$webglobal['file_company']['dataarray'][$tempdata['id']] = $tempdata;
		}
	}
}

template_Display('company', 1);
